clear
**imports Excel Spreadsheet with data; 
**"firstrow" indicates first row contain variable names. 
import excel "C:\Users\rvanwie\Desktop\Iraq.xlsx", firstrow
saveold "C:\Users\rvanwie\Desktop\ISF.dta", replace
clear

use "C:\Users\rvanwie\Desktop\ISF.dta",clear
log using "ISF.log", replace


**Stairstep OLS Regressions... When including ISF in the final regression, USF seems to maintain previous non-sig, negative coef. 
**Including ISF Doesn't radically alter USF impact on SIGACTs...
reg SIGACTS USF
reg SIGACTS USF CoalitionF
reg SIGACTS USF CoalitionF Percap_GDP
reg SIGACTS USF CoalitionF Percap_GDP Judges
reg SIGACTS USF CoalitionF Percap_GDP Judges Surge
reg SIGACTS USF CoalitionF Percap_GDP Judges Surge All_ISF 

**Using TForce Ratio that includes US, Iraqi, and Coalition troops/police
reg SIGACTS Percap_GDP Judges Surge COINPop_Ratio 

**Adding a one month lagged for civilian casualties(highly correlated with DV SIGACTS)
reg SIGACTS USF CoalitionF Percap_GDP Judges Surge All_ISF COINPop_Ratio LagCIVCAS

**Using TForce Ratio that includes US, Iraqi, and Coalition troops/police
reg SIGACTS Percap_GDP Judges Surge COINPop_Ratio LagCIVCAS

**LASSO: Least Absolute Shrinkage and Selection Operator (Tibshirani, 1996)
** Install LASSOPACK and PDLASSO Stata packages which assist with: 
** prediction, model selection, causal inference with regularized regression.
** For presentation of LASSOPACK, see: https://www.stata.com/meeting/uk18/slides/uk18_Ahrens.pdf
ssc install LASSOPACK
ssc install PDSLASSO

**https://www.stata.com/meeting/uk18/slides/uk18_Ahrens.pdf
** LASSO identifies regressors that contribute little to model fit. 
** See page 20 for notes on choosing appropriate lambda for penalty.
**For LASSO below, I am using "lasso2" command which uses information criteria for model selection (i.e. AIC).
**As λ decreases, predictors are added to the model. 
**The last column on the right indicates which predictors enter or leave the active set. 
lasso2 SIGACTS USF CoalitionF Percap_GDP Judges Surge All_ISF COINPop_Ratio LagCIVCAS
lasso2, plotpath(norm) plotlabel plot(legend(off))

**"lic(aic) selects a model based on Akaike information criterio (AIC)
** displays both LASSO and post-estimation OLS estimates
lasso2, lic(aic)

**For LASSO below, I am using "cvlasso" command which uses cross validation
**Resamples data to find lambdas that optimize out of sample prediction. 
cvlasso SIGACTS USF CoalitionF Percap_GDP Judges Surge All_ISF COINPop_Ratio LagCIVCAS, seed(123)


** "cvlasso, lse" identifies the largest lamba with MSPE that is within one standard error of the minimal MSPE
cvlasso, lse


** "cvlasso, lopt" selects the lambda that minimizes the MSPE
cvlasso, lopt


**For LASSO below, I am using "rlasso" command applies rigorous penalization for heteroskedastic and non-Gaussian errors. 
** rlasso command reports best model on first call based on algorithms that estimate optimal penalty levels. 
** rlasso allows you to work with fixed effects models and use clustered errors so we can test Shapiro, et al FE model. 
rlasso SIGACTS USF CoalitionF Percap_GDP Judges Surge All_ISF COINPop_Ratio LagCIVCAS



log close
translate "ISF.log" "ISF.pdf"
